package cn.ydt.ydt.resource.utils;

import cn.ydt.ydt.common.exception.YdtServiceException;
import cn.ydt.ydt.common.resful.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;

public class RenameUtils {

    /**
     * 文件名称替换工具，将文件名称替换为随机名称
     * @param oldName
     * @return
     */
    public static String generateFileName(String oldName){
        String suffix = oldName.substring(oldName.lastIndexOf("."));
       if (suffix.equalsIgnoreCase(".jpg")||suffix.equalsIgnoreCase(".png")){
           return IDUtils.generateUniqueId()+suffix;
       }
        throw new YdtServiceException(StatusCode.FAIL_FILEUPLOAD,"图片类型必须为jpg或png格式");
    }
}
